import javax.swing.JTable;


public class StringUtils {
	/**
	  * �ж��ַ��Ƿ�������
	  */
	 public static boolean isInteger(String value) {
	  try {
	   Integer.parseInt(value);
	   return true;
	  } catch (NumberFormatException e) {
	   return false;
	  }
	 }

	 /**
	  * �ж��ַ��Ƿ��Ǹ�����
	  */
	 public static boolean isDouble(String value) {
	  try {
	   Double.parseDouble(value);
	   if (value.contains("."))
	    return true;
	   return false;
	  } catch (NumberFormatException e) {
	   return false;
	  }
	 }

	 /**
	  * 判断是不是数字
	  */
	 public static boolean isNumber(String value) {
	  return isInteger(value) || isDouble(value);
	 }
	 public static String table2string(JTable table){
		 String string = "{";
		 int height = table.getRowCount();
		 int width = table.getColumnCount();
			for (int i = 0; i < height; i++) {
				//��
				for (int j = 0; j < width; j++) {
					String 	value = table.getModel().getValueAt(i, j).toString();
					if(j+1<width){
						string+=value+" , ";
					}else{
						string +=value;
					}
				}
				string +=" ; ";
			}
		 string+=" }";
		 System.out.println(string);
		 return string;
	 }
	 /**
	  * ת��Ϊsci��ʽ�ַ�
	  * @param value
	  * @return
	  */
	 public static String format4Table2sci(String value){
		 System.out.println(value.indexOf("], ["));
		 value = value.replaceAll("], [", ";");
		 value = value.replaceAll("[[", "{");
		 value = value.replaceAll("]]", "}");
		 return "begin = "+value;
	 }
	 /**
	  * ת��scilabType��String�����table��String[][]
	  * @param value
	  * @param height
	  * @param width
	  * @return
	  */
	 public static String[][]  format4sci2table(String value ,int height,int width){
		 String[][] data = new String[height][width];
		 int row = 0;
		 int col = 0;
		 String table =value.substring(1, value.length()-1).replaceAll(" ", "");
		 String goon;
		 for(int rows=1 ;rows<=height;rows++){
			 if(rows==height){
				 goon = table;
			 }
			 else {
				 row = table.indexOf(";");
				 goon = table.substring(0, row);
				 table=table.substring(row+1	, table.length());
			 }
			 
			 for(int cols=1;cols<=width;cols++){
				 if(cols==width){
					 data[rows-1][cols-1]=goon;
				 }else{
					col =  goon.indexOf(",");
					data[rows-1][cols-1]=goon.substring(0, col) ;
					goon = goon.substring(col+1, goon.length());
				 }
				
			 }
		 }
			 
		 return data;
	 }

	 public static final String BEGIN ="begin";
}
